﻿#coding: utf-8

require 'dm-validations'
require 'json'

class User
	include DataMapper::Resource

	property :id, Serial
	property :login, Text, :required => true
	property :password, Text, :required => true
	property :mail, Text, :required => true
	property :lastname, Text, :required => true
	property :firstname, Text, :required => true
	property :isAdmin, Boolean, :default => false
	property :created_at, Time
	property :updated_at, Time


	def to_json(*a)
		{
			'login' => login,
			'password' => password,
			'mail' => mail,
			'lastname' => lastname,
			'firstname' => firstname,
			'isAdmin' => isAdmin,
			'date' => updated_at.to_i
		}.to_json(*a)
	end
end
